---@class RankMissionItem
local RankMissionItem = Class("RankMissionItem")
---@param obj GComponent
function RankMissionItem:Bind(obj)
    self.taskText = obj:GetChild("TaskInfo")
    ---@type GController
    self.ctrl = obj:GetController("c1")
end
function RankMissionItem:Refresh(taskData)
    self.ctrl.selectedIndex = taskData["status"] >= 1 and 1 or 0
    local curConfig = G.dataTable["t_task"][tostring(taskData["taskId"])]
    self.taskText.text =getLanguage(curConfig.f_TaskDesc)  --UITaskInfo.tempNum;
end
function RankMissionItem:OnDestroy()
    self.taskText = nil
    self.ctrl = nil
end

---@class UIPlayerRankPanel
UIPlayerRankPanel = Class("UIPlayerRankPanel")

function UIPlayerRankPanel:ctor()
    self.poolMgr = logicMgr.PoolManager.New(RankMissionItem,true)
end
---@param obj GComponent
function UIPlayerRankPanel:Bind(obj)
    ---@type GList
    self.itemList = obj:GetChild("itemGrid")
    self.btnBreak = obj:GetChild("btnWeak")
    self.btnBreak.onClick:Clear()
    self.btnBreak.onClick:Add(self.ClickBreak,self)
end
function UIPlayerRankPanel:Refresh()
    self.curHeroData = logicMgr.HeroManager.getMyself()
    local serchID=self.curHeroData["partnerModelId"]*10 + self.curHeroData["star"]
    self.heroRankConfig = G.dataTable["t_herorank"][tostring(serchID)]
    local table_banch = {};
    local costTask=decodeJsonStrToTabel(self.heroRankConfig.f_RankUpTask)
    local ShowRankUp=0;
    for i=1,#costTask do
        local singleTask={}
        --singleTask=taskInfo[tostring(costTask[i])];
        local tkID=costTask[i]
        singleTask["taskId"]=tkID;
        singleTask["status"]=taskInfoHandler.GetTaskInfo(tostring(tkID))["status"];
        if(singleTask["status"]>=1)then
            ShowRankUp=ShowRankUp+1
        end
        table.insert(table_banch,singleTask);
    end
    self.btnBreak.visible = ShowRankUp >=#costTask
    self.itemList:RemoveChildrenToPool()
    for k,v in pairs(table_banch) do
        local item = self.itemList:AddItemFromPool()
        ---@type RankMissionItem
        local s = self.poolMgr:GetBindScript(item)
        s:Refresh(v)
    end
end
function UIPlayerRankPanel:ClickBreak()
    if(self.curHeroData["star"]>=logicMgr.HeroManager.LimitStar())then
        UISysTips.AddMsg(getLanguage("Sys_HeroFullRank"));
        return;
    end
    if(self.heroRankConfig.f_HeroStarNext==0)then
        UISysTips.AddMsg(getLanguage("ErrorCode_70"));
        return;
    end
    partnerHandler.sendUpStarMessage(self.curHeroData["partnerId"],ItemManager.getItemCountbyModelId(curHeroData.storeId) )
end

function UIPlayerRankPanel:OnDestroy()
    self.btnBreak.onClick:Clear()
    self.itemList = nil
    self.btnBreak = nil
    self.poolMgr:OnDestroy()
    self.poolMgr = nil
    self.heroRankConfig = nil
    self.curHeroData = nil
end




return UIPlayerRankPanel